package com.lanou.mynews.movie;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.lanou.mynews.R;

import java.util.List;


public class ReviewActivity extends Activity{
    private ListView listView;//定义一个列表组件
    private ReviewAdapter reviewAdapter;//定义一个自定义适配器
    private List<Review.CommentListEntity> picture;
    private RequestQueue requestQueue;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.review_listview);

        requestQueue = Volley.newRequestQueue(this);// 初始化请求队列

        listView = (ListView) findViewById(R.id.listview1);

        String getUrl = "http://mobileif.maizuo.com/mobileFeed1.2/"+getIntent().getStringExtra("id")+"/0,10?topFlag=0&userID=17530478f8dbcb8d149e1f4c6686b4f5&sessionkey=&type=";
        Log.i("url", getUrl);
        StringRequest request = new StringRequest(getUrl,
                new Response.Listener<String>() {

                    @Override
                    public void onResponse(String response) {// 网址正确的时候会回调的方法
                        if (response != null) {// response是从网络返回的全部数据,字符串类型
                            Gson gson = new Gson();
                            // 将解析的字符串类型的值,转成TicketResult中的格式
                            Review result = gson.fromJson(response,
                                    Review.class);
                            if (result != null && result.getCommentList()!= null) {
                                picture = result.getCommentList();
                                Log.d("lanou", "onResponse() called with: " + "response = [" + response + "]");

                                //绑定适配器
                                reviewAdapter = new ReviewAdapter(ReviewActivity.this, picture);
                                listView.setAdapter(reviewAdapter);

                            }
                        }
                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                // TODO Auto-generated method stub

            }
        });
        // 将图片请求对象加入到请求队列中
        requestQueue.add(request);

//    }

    }
}
